// 路由守卫
import { FC, ReactElement } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import userInfoUtil from '@/utils/userInfo';
interface AuthGuardProps {
  children: ReactElement;
}

const AuthGuard: FC<AuthGuardProps> = ({ children }) => {
  const location = useLocation();
  const token = userInfoUtil.getUserInfo().uname;

  if (!token) {
    return <Navigate to="/login" state={{ from: location }} replace />;
  }

  return children;
};

export default AuthGuard; 